package com.example.transitioningfragment;



import com.example.transitioningfragment.fragment.Fragment1;
import com.example.transitioningfragment.fragment.Fragment2;
import com.example.transitioningfragment.fragment.Fragment3;
import com.example.transitioningfragment.fragment.Fragment_Start;

import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends FragmentActivity implements android.view.View.OnClickListener {

	Button btn1, btn2, btn3;
	FragmentManager fr;
	FragmentTransaction ft;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		btn1 = (Button) findViewById(R.id.btn1);
		btn2= (Button) findViewById(R.id.btn2);
		btn3= (Button) findViewById(R.id.btn3);
		
		fr =  getSupportFragmentManager();
		ft= fr.beginTransaction();
		
		Fragment_Start mFragmentStart= new Fragment_Start();
		ft.add(R.id.fragmentMain, mFragmentStart);
		ft.commit();
		btn1.setOnClickListener(this);
		btn2.setOnClickListener(this);
		btn3.setOnClickListener(this);
		
 	}
	
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}



	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v!=null){
			Fragment newFragment;
			if(v.getId()==R.id.btn1){
				newFragment= new Fragment1();
			}else if( v.getId()==R.id.btn2){
				newFragment= new Fragment2();
			}else if (v.getId()==R.id.btn3){
				newFragment= new Fragment3();
			}else{
				newFragment =  new Fragment_Start();
			}
			ft=fr.beginTransaction();
			ft.replace(R.id.fragmentMain, newFragment);
			ft.addToBackStack(null);	
			ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
			ft.commit();
		}
	}



	

}
